home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Python-1.4 / Docs / Amiga / Dos_module < prev    next >
Text File  |  1998-06-24  |  9KB  |  271 lines

  1.  
  2. ***************************************************************************
  3.  
  4.                         PYTHON dos.library SUPPORT
  5.  
  6.                           dos and doslib modules
  7.     
  8.                      by Irmen de Jong - ijong@gak.nl
  9.  
  10.                           Last update: 31-Dec-96
  11.  
  12.                                BETA VERSION
  13.  
  14. ***************************************************************************
  15.  
  16. As  this  document  describes  the  BETA VERSION of the dos.library support
  17. there  might come changes to what is described below.  This depends on bugs
  18. found  and  suggestions received.  So please:  test the dos.library support
  19. and let me hear any problems/bugs/suggestions (ijong@gak.nl).
  20.  
  21.  
  22. ***************************************************************************
  23.  
  24.                               MODULE: doslib
  25.  
  26.                             FILE: N/A (builtin)
  27.  
  28. ***************************************************************************
  29.  
  30. This module provides the low-level dos.library functionality.
  31.  
  32. IMPORTANT:   It  is  DISCOURAGED  to  use this module directly, use the dos
  33. module  instead  (see  below).  The dos module imports everything from this
  34. module  so  you can access everything through the dos module instead.  This
  35. is  much  like  how the string module uses the builtin strop module:  don't
  36. use the builtin lowlevel module directly!
  37.  
  38. This module defines the following exception:
  39.  
  40.   error        - The exception that will be raised when an
  41.           error occurs related to dos.library. ('doslib.error')
  42.  
  43.  
  44. +--------------------------------------+
  45. |                                      |
  46. |          DEFINED FUNCTIONS           |
  47. |                                      |
  48. +--------------------------------------+
  49.  
  50. ReadArgs
  51.     INTENTIONALLY UNDOCUMENTED. USE ArgParser CLASS FROM `dos' MODULE!
  52.  
  53. WaitSignal(what)
  54.     Generic Wait() function to wait for signals, modeled after the `select'
  55.     function. Usage: (sigs,objlist) = WaitSignal(what)
  56.        what = integer, object, or a list of ints and/or objects.
  57.        Integers are sigmask values. Objects must have a 'signal' attribute
  58.        which is their sigmask value. When a list is given the sigmasks of
  59.        the items are or-ed together (max 32 items).
  60.     RESULT: sigs = the signals that occured (sigmask).
  61.             objlist = a list of the objects whose signal occured.
  62.     NOTE: any signals that were detected are cleared when WaitSignal()
  63.     returns. Signals that were not waited upon are not cleared.
  64.  
  65. CheckSignal(what)
  66.     Like WaitSignal (see above) but DOESN'T WAIT, merely checks if certain
  67.     signals are set. NOTE: any signals that were detected are cleared when
  68.     CheckSignal() returns. Signals that were not checked upon are not
  69.     cleared.
  70.  
  71. CompareDates(d1,d2)
  72.     Compares the two 3-tuple DateStamps d1 and d2 and returns:
  73.     <0 if d1 is later than d2
  74.      0 if d1 = d2
  75.     >0 if d1 is before d2
  76.  
  77. DateStamp()
  78.     Returns 3-tuple AmigaDOS DateStamp (current date & time).
  79.  
  80. DateToStr(date,format=FORMAT_DOS,flags=0)
  81.     Convert 3-tuple DateStamp to readable 3-tuple date string.
  82.     date = DateStamp
  83.     format and flags are optional.
  84.     format = how to format the string (see dos.py module for definitions)
  85.     flags = flags (see dos.py module for definitions)
  86.     
  87. StrToDate(dstr [,timestring, format = FORMAT_DOS, flags = 0] )
  88.     Convert AmigaDOS date string to AmigaDOS DateStamp.
  89.     dstr = date string (like '27-Aug-96')
  90.     timestring = time string (optional, like '16:12:00')
  91.     format = string format (optional, see dos.py module for definitions)
  92.     flags = flags (see dos.py module for definitions)
  93.     
  94. Fault(err [,header])
  95.     Returns DOS error message string.
  96.     err = dos error code
  97.     header = error header string (optional, defaults to None which means
  98.              no header)
  99.  
  100. IoErr()
  101.     Returns last DOS IoErr() error value.
  102.  
  103. SetIoErr(err)
  104.     Set new DOS IoErr() error value, and returns previous value.
  105.  
  106. IsFileSystem(path)
  107.     Checks if path is a filesystem device.
  108.  
  109. Relabel(oldvolname,newvolname)
  110.     Relabel a disk.
  111.     oldvolname = old volume name (including :)
  112.     newvolname = new volume name (without :)
  113.     
  114. SetProtection(file,protbits)
  115.     Set DOS file protection bits.
  116.     file = filename
  117.     protbits = protection bits for this file (see dos.py module for
  118.                definitions)
  119.  
  120. SetComment(file,comment)
  121.     Set DOS file comment string.
  122.     file = filename
  123.     comment = file comment string for this file
  124.     
  125. Examine(file)
  126.     Examine a file or directory. Returns the following tuple:
  127.     (filename,size,type,protection,diskkey,#blocks,
  128.      3-tuple DateStamp, comment, owner UID, owner GID )
  129.  
  130. DS2time(ds)
  131.     Convert DateStamp tuple to time() value (see time module)
  132.  
  133. time2DS
  134.     Convert time() value (see time module) to DateStamp tuple
  135.  
  136.  
  137.  
  138.  
  139.  
  140. ***************************************************************************
  141.  
  142.                                 MODULE: dos
  143.  
  144.                                FILE: dos.py
  145.  
  146. ***************************************************************************
  147.  
  148. This module is the interface to the Amiga's dos.library.
  149.  
  150. IMPORTANT:  this module uses the builtin doslib module.  Don't use it
  151. yourself directly, always use the `dos' module.
  152.  
  153. NOTE:
  154.  The whole lot of dos LVO's that are not covered are considered:
  155.     - not useful;
  156.  or - unsafe (with regards to memory/lists/nodes/structs etc);
  157.  or - very difficult to use from Python.
  158.  Check the os and (amiga)path modules for things like file I/O,
  159.  path operations and other stuff.
  160.  
  161.  
  162. This module defines the following exception:
  163.  
  164.   error        - The exception that will be raised when an
  165.           error occurs related to dos.library. ('doslib.error')
  166.           This is the same exception as the one from
  167.           the builtin doslib module.
  168.  
  169.  
  170. +--------------------------------------+
  171. |                                      |
  172. |          DEFINED FUNCTIONS           |
  173. |                                      |
  174. +--------------------------------------+
  175.  
  176. As  this  module  imports everything from the doslib module, see above what
  177. functions  are  provided.  Use the functions through this module, don't use
  178. the doslib module directly.
  179.  
  180.  
  181. +--------------------------------------------+
  182. |                                            |
  183. |  DEFINED CONSTANTS (taken from dos/dos.h)  |
  184. |                                            |
  185. +--------------------------------------------+
  186.  
  187. - The break flags, SIGBREAKF_CTRL_C to SIGBREAKF_CTRL_F.
  188. - AmigaDOS file protection bits, including the `group' and `other' bits.
  189. - Flags and Format definitions for DateToStr and StrToDate.
  190.  
  191.  
  192. +--------------------------------------+
  193. |                                      |
  194. |          ARGPARSER CLASS             |
  195. |                                      |
  196. +--------------------------------------+
  197.  
  198. This  module  defines  the  ArgParser  class,  which  is an argument string
  199. parser.   It  can  be  used to parse ReadArgs() argument strings (the usual
  200. Amiga  style  for  command  lines,  all  CLI commands use it).  It works as
  201. follows:
  202.  
  203. p = dos.ArgParser(template)
  204.  
  205.     Create new parser for the specified template.
  206.     template = ReadArgs template, like 'FROM/A/M,TO/A,QUIET/S'. 
  207.     
  208.     When parsing an argument string (see below) the type of the returned
  209.     Python value depends on the type of the argument in the template,
  210.     f.i. /N arguments will return an integer value.
  211.     `Multi'-options will ofcourse return a list.
  212.  
  213.     NOTE: /T (Switch Toggle) options are not supported.
  214.           (SystemError will be raised when you try to use /T)
  215.  
  216.     NOTE: ValueError will be raised when the template is considered
  217.           invalid.
  218.  
  219.  
  220. ** ArgParser objects have the following attributes:
  221.  
  222. defaults    - dictionary which contains the default values for each
  223.           template option which is not required (i.e. which is not
  224.           specified with /A switch). YOU MAY MODIFY THIS to change
  225.           the default options!!!
  226. template    - the template string. DO NOT MODIFY THIS! (use the `new'
  227.           member function to change the template)
  228. types        - internal type tuple. DO NOT MODIFY THIS! The structure is
  229.           as follows: ( (<template option>, <option type>), ... )
  230.           For instance when the template is 'FROM/A/M,TO/A,QUIET/S'
  231.           types will be (('FROM', ??), ('TO', ??), ('QUIET', ??)).
  232.           THE TYPE ENCODING IS PRIVATE, DO NOT TRY TO USE IT.
  233.  
  234.  
  235. ** ArgParser objects have the following member functions:
  236.  
  237. new(template)
  238.     modify the parser to use the new template
  239.  
  240. reset()
  241.     re-initialise the parser; reset defaults dictionary
  242.  
  243. parse(args)
  244.     The important one: parse the argument string args according to the
  245.     template of this ArgParser. Returns a dictionary containing the actual
  246.     arguments. The defaults dictionary is used to substitute default values
  247.     for unspecified arguments. Example:
  248.  
  249.     >>> p=dos.ArgParser('FROM/A/M,TO/A,QUIET/S')
  250.     >>> p.defaults
  251.     {'QUIET': 0}
  252.     >>> p.types
  253.     (('FROM', 'A'), ('TO', 'X'), ('QUIET', 'S'))
  254.     >>> p.template
  255.     'FROM/A/M,TO/A,QUIET/S'
  256.     >>> p.parse('C:')
  257.     doslib.error: You've forgotten an argument
  258.     >>> p.parse('C: ram:')
  259.     {'FROM': ['C:'], 'TO': 'ram:', 'QUIET': 0}
  260.     >>> r=p.parse('c:dir c:list c:copy TO RAM: quiet')
  261.     >>> print r
  262.     {'FROM': ['c:dir', 'c:list', 'c:copy'], 'TO': 'RAM:', 'QUIET': -1}
  263.     >>> for (o,t) in p.types: print 'Arg for',o,'is',r[o]
  264.     Arg for FROM is ['c:dir', 'c:list', 'c:copy']
  265.     Arg for TO is RAM:
  266.     Arg for QUIET is -1
  267.  
  268. Other member functions ARE PRIVATE.
  269.  
  270.   
  271.